//---------------------------------------------------------------------------

#ifndef CIIClientSocketH
#define CIIClientSocketH
#include "DebugWinU.h"
#include <scktcomp.hpp>

//---------------------------------------------------------------------------

class TCIIClientSocket : public TObject
{
private:
  TDebugWin *DW;
  TList *MessageList, *ResponseList;
  TClientSocket *ClientSocket;
  TCustomWinSocket *CWSocket;
  TTimer *TimerSRead;
  MessInQueueFP MInQ;

  unsigned char SocketInBuf[SocketInBufSize];
  unsigned char SocketOutBuf[SocketOutBufSize];
  unsigned char SocketInputQueue[SocketInputQueueSize];

  String IPAdr;
  int SocketInputIdx, PortNo;
  Word ResponseCount;
  bool ContSocketRead, FServerConnected;

  void __fastcall Debug(String Message);
  void __fastcall AddSocketInputQueue(char* Buf, int N);
  bool __fastcall ParseMessages();

protected:

public:
  __fastcall TCIIClientSocket(MessInQueueFP SetMInQ, String SetIP, int SetPortNo, TDebugWin * SetDebugWin);
  __fastcall ~TCIIClientSocket();

  TCamurPacket* __fastcall GetReply(int RequestNo);
  void __fastcall SendMessage( TCamurPacket *Request );

  void __fastcall ServerConnect(TObject * Sender, TCustomWinSocket * Socket);
  void __fastcall ServerLookup(TObject * Sender, TCustomWinSocket * Socket);
  void __fastcall ServerDisconnect(TObject * Sender, TCustomWinSocket * Socket);
  void __fastcall ServerOnError(TObject *Sender, TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode);
  void __fastcall ServerRead(TObject * Sender, TCustomWinSocket * Socket);
  void __fastcall SetDebugWin(TDebugWin * SetDebugWin);
  void __fastcall TimerSReadEvent(TObject * Sender);
        void __fastcall OpenCom(String SetIP);
        void __fastcall CloseCom();


__published:
    __property bool ServerConnected  = { read=FServerConnected };

};
#endif
